from pynput.keyboard import Controller
import time

key = input('请确认已经将文本放在了data.txt文件内！确认后请敲击回车！')
print(f'注意：放置光标后的英文还有中文输入！')
for i in range(5):
    print(f'程序还有 {5-i} 秒启动')
    time.sleep(1)

# 修复以下内容 (Fix these parts)
file_path = r'data.txt'  # 修改为你要读取的真实文件
try:
    with open(file_path, 'r', encoding='utf-8') as f:  # 添加编码参数
        data = f.read()
except FileNotFoundError:
    print(f"错误：文件 {file_path} 不存在！")
    exit()

keyboard = Controller()
for char in data:
    keyboard.type(char)
    time.sleep(0.01)  # 推荐添加短暂延迟